package propcalc_lang.ast;

import java.util.Random;

/** Tautología, válida si la proposición es siempre verdadera independientemente
 *  de los valores de sus variables proposicionales.
 *  @author Leonardo Val.
 */
public class Tautology extends Formula {
	public final Proposition proposition;
	
	public Tautology(Proposition proposition) {
		this.proposition = proposition;
	}

	@Override public String unparse() {
		return "|= "+ proposition.unparse();
	}

	public static Tautology generate(Random random, int min, int max) {
		return new Tautology(Proposition.generate(random, min-1, max-1));
	}
	
	@Override public String toString() {
		return "Tautology("+ proposition +")";
	}

	@Override public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((proposition == null) ? 0 : proposition.hashCode());
		return result;
	}

	@Override public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tautology other = (Tautology) obj;
		if (proposition == null) {
			if (other.proposition != null)
				return false;
		} else if (!proposition.equals(other.proposition))
			return false;
		return true;
	}

}
